/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain.threads;


import Server.domain.BomberManGameServer;
import Server.domain.PlayerList;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 *
 * @author user
 */
public class BomberManGameServerThread extends Thread
{
    protected DatagramSocket socket = null;
    protected DatagramPacket packet = null;
    private BomberManGameServer bmServer;
  

    public BomberManGameServerThread(BomberManGameServer server) {
      super("Game Server Thread");

		
		try
		{
                        this.bmServer = server;
			//creates the socket
			socket = new DatagramSocket(server.getUdpPort());
                        bmServer.setSocket(socket);
			System.out.println(InetAddress.getLocalHost().getHostName());
			System.out.println(InetAddress.getLocalHost().getHostAddress());
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
    }
    
   public void run()
	{
		while(bmServer.isRunning())
		{
			try
			{
				bmServer.receivePacket();
				bmServer.sendPacket();
			}
			catch(IOException e)
			{
				e.printStackTrace();
				bmServer.setRunning(false);
			}
		}
		socket.close();
	}
	
}
